/*************************************************
* Copyright(c) free                              *
* Beijing Jiaotong University                    *
* TEAM: Wasabi                                   *
* AUTHOR: Li Wei          			 *
* This file is used to achomplish the action of  *
* the window's controls,like the label,command,  * 
* radio,menu.                                    * 
* Version 1.0 2011-01-6                          *
*************************************************/

#include <stdio.h>
#include <sys/stat.h> /* Join in the relevant document information operations include header files */
#include <unistd.h>
#include <gtk/gtk.h>
#include "../include/convert.h"
#include "../include/callbacks.h"
#include <string.h>
#include "../include/logo2.h"

extern GtkWidget * view1, * view2;/* Extern define in interface.c */
extern GtkTextBuffer * buffer1, *buffer2;
extern GtkClipboard * clipboard;
extern gboolean flag, flagv;/* programe selection */
extern GtkWidget * radio1,* radio2;
extern GtkWidget * radio3,* radio4;
extern GtkWidget * view_vbox, *view_hbox;
extern GtkItemFactoryEntry menu_items[];

static GtkWidget *yesno_dialog = NULL;
static GtkWidget *open_dialog = NULL;
static GtkWidget *save_dialog = NULL;
const gchar *filename = NULL;
static gboolean file_modifyed = FALSE;
static gboolean is_new= FALSE;

static void open_file (gpointer data);
static void real_open (gpointer data);
static void store_filename (GtkFileSelection *selector, gpointer user_data);
static void set_window_title (GtkWidget *window);
static void save_file (gpointer data);
static void real_save (gpointer data);
static void view_v2h ();
static void view_h2v ();
extern GtkWidget* frame1;
extern GtkWidget* frame2;
extern GtkWidget* frame11;
extern GtkWidget* frame22;
extern GtkWidget *scwin1, *scwin2;
gboolean flagn;
static void ok1 ();
static void ok2 ();

/***************************************************************************************************
 on_file_open_activate : to accept the open action from the window.
 parameter : GtkMenuItem *menuitem 
	     Accept the action of the specific GTK components. 
	     
	     gpointer data
             A pointer designated by programmers.
 return type : null.
 detail descrpition : Response file - open menu items, open the file browser, choose a file open, specified by customer files coding, then let the contents of the documents shown in the input box.            
****************************************************************************************************/
void on_file_open_activate (GtkMenuItem *menuitem,gpointer data){
    open_file((gpointer)view1);
}


/***************************************************************************************************
 on_file_save_activate : to accept the save aciton from the window.
 parameter : GtkMenuItem *menuitem 
	     Accept the action of the specific GTK components. 
	     
	     gpointer data
             A pointer designated by programmers.
 return type : null.
 detail descrpition : Response file - saving menu items, will input box of the contents of the save to file, save when specified by customer preservation coding.            
****************************************************************************************************/
void on_file_save_activate (GtkMenuItem *menuitem,gpointer data){
    save_file((gpointer)view2);
}


/***************************************************************************************************
 on_file_exit_activate : to accept the exit action from the window.
 parameter : GtkMenuItem *menuitem 
	     Accept the action of the specific GTK components. 
	     
	     gpointer data
             A pointer designated by programmers.
 return type : null.
 detail descrpition : Response file - exit menu items, before exit if had romanji operation, whether need to prompt the user will romanji results save to file.             
****************************************************************************************************/
void on_file_exit_activate (GtkMenuItem *menuitem,gpointer data){
    on_window_delete_event (NULL,"delete_event");
}


/***************************************************************************************************
 on_reset_activate : to accept the reset action from the window. 
 one encode to anther.
 parameter : GtkMenuItem *menuitem 
	     Accept the action of the specific GTK components. 
	     
	     gpointer data
             A pointer designated by programmers.
 return type : null.
 detail descrpition : Response operation - screen clearing menu items, empty input box and output from the box full content. Before clear, show the dialog box for user to validate the action.             
****************************************************************************************************/
void on_reset_activate (GtkMenuItem *menuitem,gpointer data){
    GtkTextIter iter;
    GtkTextIter start, end;

    gtk_text_buffer_get_start_iter(buffer1, &start);
    gtk_text_buffer_get_end_iter(buffer1, &end);
    gtk_text_buffer_delete(buffer1, &start, &end);/* all clear */

    gtk_text_buffer_get_start_iter(buffer2, &start);
    gtk_text_buffer_get_end_iter(buffer2, &end);
    gtk_text_buffer_delete(buffer2, &start, &end);/* all clear */
}


/***************************************************************************************************
 view_h2v : cnovert the window's view from horizontal to verticle.
 parameter : null.
 return type : null.
 detail descrpition : Convert the window's view from horizontal to verticle.             
****************************************************************************************************/
void view_h2v (){
    gtk_widget_ref(scwin1);
    gtk_widget_ref(scwin2);
    gtk_container_remove(GTK_CONTAINER(frame11),scwin1);
    gtk_container_remove(GTK_CONTAINER(frame22),scwin2);
    gtk_container_add(GTK_CONTAINER(frame1),scwin1);
    gtk_container_add(GTK_CONTAINER(frame2),scwin2);
    gtk_widget_unref(scwin1);
    gtk_widget_unref(scwin2);		
    gtk_widget_show(view_vbox);		
    gtk_widget_hide(view_hbox);
			
}


/***************************************************************************************************
 view_v2h : cnovert the window's view from horizontal to verticle.
 parameter : null.
 return type : null.
 detail descrpition : Convert the window's view from vertical to horizontal.             
****************************************************************************************************/
void view_v2h (){
    gtk_widget_ref(scwin1);
    gtk_widget_ref(scwin2);
    gtk_container_remove(GTK_CONTAINER(frame1),scwin1);
    gtk_container_remove(GTK_CONTAINER(frame2),scwin2);
    gtk_container_add(GTK_CONTAINER(frame11),scwin1);
    gtk_container_add(GTK_CONTAINER(frame22),scwin2);
    gtk_widget_unref(scwin1);
    gtk_widget_unref(scwin2);	
    gtk_widget_show(view_hbox);		
    gtk_widget_hide(view_vbox);
			
}


GtkWidget create_dialog (void);

gboolean on_window_delete_event (GtkWidget * widget, gpointer data){
    gtk_main_quit();
    return FALSE;

}


/***************************************************************************************************
 store_filename : to accept the action from the file selector.
 parameter : GtkFileSelection *selector
             Accept the action of the selector.

             gpointer user_data
             accept the choosen option. 
 return type : null.
 detail descrpition : Response algorithm single box, designated needs to perform arithmetic. After selecting, algorithm to select menu of choice should be consistent with this.             
****************************************************************************************************/
static void store_filename (GtkFileSelection *selector, gpointer user_data){
    filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION (user_data));
    if (g_file_test(filename,G_FILE_TEST_IS_DIR))
        flagn = FALSE;
    else 
        flagn = TRUE;
}


/***************************************************************************************************
 on_radio_clicked : to accept the action from the programe selection radio
 parameter : GtkWidget *radio
             Accept the action of the radio.

             gint data
             accept the choosen option. 
 return type : null.
 detail descrpition : Response algorithm single box, designated needs to perform arithmetic. After selecting, algorithm to select menu of choice should be consistent with this.             
****************************************************************************************************/
void on_radio_clicked (GtkWidget *radio, gint data){
    switch((int)data){
        case 1:
	    flag = FALSE;
	    //gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem3_1), TRUE);
            //gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem3_2), FALSE);		
	    break;
	case 2:
	    flag = TRUE;
            //gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem3_2), TRUE);
	    //gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem3_1), FALSE);
	    break;	
    }
}


/***************************************************************************************************
 on_radio_clicked : to accept the action from the programe selection radio
 parameter : GtkWidget *radio
             Accept the action of the radio.

             gint data
             accept the choosen option. 
 return type : null.
 detail descrpition : Response algorithm single box, designated needs to perform arithmetic. After selecting, algorithm to select menu of choice should be consistent with this.             
****************************************************************************************************/
void on_radio2_clicked (GtkWidget *radio, gint data){
    switch((int)data){
	case 1:
            if (flagv == FALSE)
                break;
	    else{
                flagv = FALSE;
	        view_h2v();
                //gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem4_1), TRUE);
		//gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem4_2), FALSE);
	        break;
            }
	case 2:
            if (flagv == TRUE)
                break;
	    else {
	        flagv = TRUE;
	        view_v2h();
                //gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem4_2), TRUE);
		//gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem4_1), FALSE);
		break;
            }
	}
}


/***************************************************************************************************
 on_v_view_activate : to accept the action from the window's view component.
 parameter : GtkMenuItem *menuitem
             Accept the action of the specific GTK components. 

             gpointer data
             A pointer designated by programmers. 
 return type : null.
 detail descrpition : Selection of input and output box from the vertical view.             
****************************************************************************************************/
void on_v_view_activate (GtkMenuItem *menuitem,gpointer data){
    if (flagv == TRUE){
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio3),TRUE); 
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio4),FALSE);    
        view_h2v();
        flagv = FALSE;
    }
			
}


/***************************************************************************************************
 on_h_view_activate : to accept the action from the window's view component.
 parameter : GtkMenuItem *menuitem
             Accept the action of the specific GTK components. 

             gpointer data
             A pointer designated by programmers. 
 return type : null.
 detail descrpition : Selection of input and output box from the horizontal view.             
****************************************************************************************************/
void on_h_view_activate (GtkMenuItem *menuitem,gpointer data){
    if (flagv == FALSE){
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio4),TRUE); 
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio3),FALSE);
	view_v2h();
        flagv = TRUE;
    }
}


/***************************************************************************************************
 on_fwd_activate : to accept the action from the window's component.
 parameter : GtkMenuItem *menuitem
             Accept the action of the specific GTK components. 

             gpointer data
             A pointer designated by programmers. 
 return type : null.
 detail descrpition : Select the maximum positive seperate words programe, after selecting, interface on single marquee state need consistent with it.            
****************************************************************************************************/
void on_fwd_activate (GtkMenuItem *menuitem,gpointer data){
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio1),TRUE); 
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio2),FALSE);
    flag = FALSE; //
}


/***************************************************************************************************
 on_back_activate : to accept the action from the window's component.
 parameter : GtkMenuItem *menuitem
             Accept the action of the specific GTK components. 

             gpointer data
             A pointer designated by programmers. 
 return type : null.
 detail descrpition : Select the maximum positive seperate words programe, after selecting, interface on single marquee state need consistent with it.            
****************************************************************************************************/
void on_back_activate (GtkMenuItem *menuitem,gpointer data){
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio2),TRUE); 
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio1),FALSE);
    flag = TRUE; //
}


/***************************************************************************************************
 on_back_activate : to read the TrieTree structure and return the chinese pinyin.
 parameter : gpointer data
             A pointer designated by programmers. 
 return type : null.
 detail descrpition : Convert the source buffer data and save the chinese pinyin result into tanscode buffer.            
****************************************************************************************************/
void zhuyin (gpointer data){
    GtkTextIter iter;
    GtkTextIter start, end;
    gchar *buf;/* Source buffer */
    gchar *buf2;/* Transcode buffer */
	
    gtk_text_buffer_get_start_iter(buffer1, &start);
    gtk_text_buffer_get_end_iter(buffer1, &end);
    buf = gtk_text_buffer_get_text(buffer1, &start, &end, TRUE);
	
    //call the convert.c Transcode and segment the sentence
    if (strcmp(buf,"")==0)
	buf2 = buf;
    else/*select the segment programe*/{
	int inLen = strlen(buf);
        int outLen;
        char *outBuf;
        int nRet;
        if(flag == FALSE)		
            nRet = TransForm( buf, &inLen, &outBuf, &outLen, 1 );
	else if (flag == TRUE)
	    nRet = TransForm( buf, &inLen, &outBuf, &outLen, 2 );
	    buf2 = outBuf;				
    }
    gtk_text_buffer_get_start_iter(buffer2, &start);
    gtk_text_buffer_get_end_iter(buffer2, &end);
    gtk_text_buffer_delete(buffer2, &start, &end);/* all clear */			
    gtk_text_buffer_insert(buffer2, &end, buf2, -1);
	
}


/***************************************************************************************************
 on_back_activate : to accept the action from the window's menu component.
 parameter : GtkMenuItem *menuitem
             Accept the action of the specific GTK components. 

             gpointer data
             A pointer designated by programmers. 
 return type : null.
 detail descrpition : to accept the aciton from the window's menu compontent.            
****************************************************************************************************/
void on_zhuyin_activate (GtkMenuItem *menuitem,gpointer data){
    zhuyin (data);
}


/***************************************************************************************************
 on_button1_clicked : to accept the action from the window's button1 click.
 parameter : GtkMenuItem *buttun
             Accept the action of the button1 click. 

             gpointer data
             A pointer designated by programmers. 
 return type : null.
 detail descrpition : Response of phonetic button, according to the current selected algorithms on the input box content pinyin annotation. If the input box is empty, remind user input. Mark after calculation tagging speed.            
****************************************************************************************************/
void on_button1_clicked (GtkWidget * buttun,  gpointer data){
    zhuyin (data);
}


/***************************************************************************************************
 on_button2_clicked : to accept the action from the window's button2 click.
 parameter : GtkMenuItem *buttun
             Accept the action of the button2 click. 

             gpointer data
             A pointer designated by programmers. 
 return type : null.
 detail descrpition : Response open button, open the file browser, choose a file open, specified by customer files coding, then let the contents of the documents shown in the input box.           
****************************************************************************************************/
void on_button2_clicked (GtkWidget * buttun, gpointer data){
    open_file(data);	
}


/***************************************************************************************************
 open_file : to accept the action from the users terminal operate.
 parameter : gpointer data
             A pointer designated by programmers. 
 return type : null.
 detail descrpition : Open file.           
****************************************************************************************************/
static void open_file (gpointer data){
    open_dialog = gtk_file_selection_new("请选择一个文本文件：");
    gtk_window_set_modal(GTK_WINDOW(open_dialog), TRUE);
    filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION (open_dialog));
    g_signal_connect_swapped (GTK_OBJECT(GTK_FILE_SELECTION(open_dialog)->ok_button),
				"clicked",
				G_CALLBACK(ok1),
				NULL);
    g_signal_connect_swapped (GTK_OBJECT(GTK_FILE_SELECTION(open_dialog)->cancel_button),
				"clicked",
				G_CALLBACK(gtk_widget_destroy),
				(gpointer)open_dialog);
    gtk_widget_show(open_dialog);

}


/***************************************************************************************************
 real_open : to accept the action from the users terminal operate.
 parameter : gpointer data
             A pointer designated by programmers. 
 return type : null.
 detail descrpition : Real open.           
****************************************************************************************************/
static void real_open (gpointer data){
    //GtkWidget * window;
    FILE * fp;
    GtkTextIter iter;
    GtkTextIter start, end;
    glong bytes_read;
    gchar *buf;/* Soruce buffer */
    gchar *dbuf;/* Destination buffer */
    gsize dlong;/* Length of the converted file */
    glong length;/* Length of the file */
    struct stat pstat;/* The status of the file, for get the length of the file */

    if (stat(filename, &pstat)==-1){
	g_printf("读取文件出错...\n");
	return;		
    }
    length = pstat.st_size;	/* Get the length of the file */
    buf = g_malloc(length);	/* Allocate the memory to buffer */
	
    gtk_text_buffer_get_start_iter(buffer1, &start);
    gtk_text_buffer_get_end_iter(buffer1, &end);
    gtk_text_buffer_delete(buffer1, &start, &end);/* All clear */
    gtk_text_buffer_get_iter_at_line_index(buffer1, &iter, 0, 0);	/*Get the sign*/
	
    fp = fopen (filename, "r"); /*Open file*/
    if (fp == NULL){
	g_print("错误：文件无法打开 \n");
	g_free(buf);
	return;	
    }
    //Judge the size of the file
/*
    int n;
    n = fseek( fp, 0, SEEK_END );

    if( n == -1 ){
	printf( "fseek to end error!\n" );
        return;
    }
    long nFileSize = ftell( fp );
         
    n = fseek( fp, 0, SEEK_SET );
    if( n == -1 ){
	printf( "fseek to start error!\n" );
        return;
    } 
   
    if ((nFileSize/1024) <= 50){
*/
        bytes_read = fread(buf, sizeof(gchar), length, fp);/* Read file */
	if (g_utf8_validate(buf, bytes_read, NULL) == FALSE){
	    //dbuf = g_locale_to_utf8(buf, length, NULL, &dlong, NULL);
	    /* convert to the UTF8 ,save the length of the file into dlong, pointer as dbuf */
	    dbuf = g_convert(buf, length,"UTF-8","GBK", NULL, &dlong, NULL);//GBK ISO-8859
	    if (bytes_read == length)
		gtk_text_buffer_insert(buffer1, &iter, dbuf, dlong);
	}
	else{
	    if (bytes_read == length)			
		gtk_text_buffer_insert(buffer1, &iter, buf, length);
		
	}
	
	if (ferror(fp)){
	    fclose(fp);
	    g_free(buf);
	    return;	
	}
	fclose(fp);
	g_free(buf);
	//window = gtk_widget_get_toplevel(GTK_WIDGET(data));
	//set_window_title(window);
    //}
/*
    else if ((nFileSize/1024) > 50){
        GtkWidget * dialog;
    	dialog = gtk_message_dialog_new(NULL,
					GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
					GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "文件大小需小于50KB，请重新选择，谢谢。");
	gtk_dialog_run(GTK_DIALOG(dialog));
	gtk_widget_destroy(dialog);
        return;
    }
*/
}


/***************************************************************************************************
 set_window_title : to accept the action from the window's component.
 parameter : GtkWidget *window
             Accept the action of the window's component. 
 return type : null.
 detail descrpition : Setting file name.           
****************************************************************************************************/
static void set_window_title (GtkWidget *window){
    gchar title[1024];
    gchar *noname = "未命名";
    if (filename != NULL)
	sprintf(title, "%s -- 打开", filename);
    else
	sprintf(title, "%s -- 打开", noname);
    gtk_window_set_title(GTK_WINDOW(window), title);

}


/***************************************************************************************************
 on_button3_clicked : to accept the action from the window's button3 click.
 parameter : GtkMenuItem *buttun
             Accept the action of the button3 click. 

             gpointer data
             A pointer designated by programmers. 
 return type : null.
 detail descrpition : Response to save button, the input box of the contents of the save to file, save when specified by customer preservation coding.           
****************************************************************************************************/
void on_button3_clicked (GtkWidget * buttun, gpointer data){
    save_file(data);
}

static void ok1 (){
    filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION (open_dialog));
    if (g_file_test(filename,G_FILE_TEST_IS_DIR)){
        gtk_widget_show(open_dialog);
    }
    else{
        real_open(view1);
        gtk_widget_destroy(open_dialog);
    }
}

static void ok2 (){
    filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION (save_dialog));
    if (g_file_test(filename,G_FILE_TEST_IS_DIR)){
        gtk_widget_show(save_dialog);
    }
    else{
        real_save(view2);
        gtk_widget_destroy(save_dialog);
    }
}


/***************************************************************************************************
 save_file : to accept the action from the users terminal operate.
 parameter : gpointer data
             A pointer designated by programmers. 
 return type : null.
 detail descrpition : Save file.           
****************************************************************************************************/
static void save_file (gpointer data){
    save_dialog = gtk_file_selection_new("请选择一个文件： ");
    gtk_window_set_modal(GTK_WINDOW(save_dialog), TRUE);
    //gtk_file_selection_set_filename (GTK_FILE_SELECTION(save_dialog),"*.txt");
    /*g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(save_dialog)->ok_button),
					"clicked",
					G_CALLBACK(store_filename),
					save_dialog);*/
    gtk_widget_show(save_dialog); 
    filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION (save_dialog));
    g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(save_dialog)->ok_button),
					"clicked",
					G_CALLBACK(ok2),
					NULL);
    g_signal_connect_swapped(GTK_OBJECT(GTK_FILE_SELECTION(save_dialog)->cancel_button),
					"clicked",
					G_CALLBACK(gtk_widget_destroy),
					(gpointer) save_dialog);
	//gtk_widget_show(save_dialog);



}


/***************************************************************************************************
 real_save : to accept the action from the users terminal operate.
 parameter : gpointer data
             A pointer designated by programmers. 
 return type : null.
 detail descrpition : Real save.           
****************************************************************************************************/
static void real_save (gpointer data){
    //GtkWidget *window;
    FILE *fp;
    GtkTextBuffer *textbuf;
    gchar *buf;
    gchar *dbuf;
    GtkTextIter start, end;
    textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view2));
    gtk_text_buffer_get_start_iter(textbuf, &start);
    gtk_text_buffer_get_end_iter(textbuf, &end);
    //filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION (save_dialog));
    fp = fopen(filename, "w");
    if (fp == NULL){
	g_print("文件为空 错误.\n");
	g_free(buf);
        g_free(buf);
	return;
    }
    buf = gtk_text_buffer_get_text(textbuf, &start, &end, TRUE);
    dbuf = g_locale_from_utf8(buf, -1, NULL, NULL, NULL);//转换为本地代码保存
    fputs(dbuf,fp);
    fclose(fp);
    //window = gtk_widget_get_toplevel(GTK_WIDGET(data));
    //set_window_title(window);

}


/***************************************************************************************************
 on_button4_clicked : to accept the action from the window's button4 click.
 parameter : GtkWidget * buttun
             Accept the action of the button4 click. 
 return type : null.
 detail descrpition : Clear the input buffer and the output buffer.           
****************************************************************************************************/
void on_button4_clicked (GtkWidget * buttun){
    GtkTextIter iter;
    GtkTextIter start, end;

    gtk_text_buffer_get_start_iter(buffer1, &start);
    gtk_text_buffer_get_end_iter(buffer1, &end);
    gtk_text_buffer_delete(buffer1, &start, &end);/* All clear */

    gtk_text_buffer_get_start_iter(buffer2, &start);
    gtk_text_buffer_get_end_iter(buffer2, &end);
    gtk_text_buffer_delete(buffer2, &start, &end);/* All clear */

}


/***************************************************************************************************
 on_man_activate : to accept the action from the window's help menu.
 parameter : GtkMenuItem *menuitem
             Accept the action of the specific GTK components. 

             gpointer data
             A pointer designated by programmers. 
 return type : null.
 detail descrpition : Help manual.           
****************************************************************************************************/
void on_man_activate (GtkMenuItem *menuitem,gpointer data){
    GtkWidget * table;
    GtkWidget * button;
    GtkWidget * dialog;
    GtkWidget * label;

    dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(dialog),550,600);
    gtk_window_set_title(GTK_WINDOW(dialog),"用户手册");
    gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER);
    label = gtk_label_new("◇关于试用：\n    欢迎您试用本拼音标注软件！您的支持，是我们创作小组的动力！\n◇责任声明:\n    在试用之前，请您仔细阅读以下几点：\n    1、本软件产品没有附带任何恶意插件或黑客程序；\n    2、试用本软件产品由试用者承担风险、责任及后果。\n    如果您没有阅读，或者不同意以上声明，请不要试用或者使用本软件产品。\n◇技术支持：\n    操作系统ubuntu 10.10 下GTK图形库的调用，动态链接库的使用。\n如有任何技术问题，请与创作小组联系。\n    E-mail：wsb127052297@126.com\n    腾讯QQ：127052297\n    本创作小组将会在升级版中陆续增加一些更多实用的功能，敬请期待！\n◇操作说明：\n    1、支持2种输入方式:键盘输入，或者点击“打开”按钮，导入文本文件(.txt)，\n	将需要标注拼音的内容输入文件内容框中；\n    2、支持文本文件编码：UTF8；\n    3、支持两种分词算法：最大正向分词、最大逆向分词；\n    4、打开文件或者直接输入文字内容后，点击“注音”按钮，可完成拼音标注；\n    5、看到注音成功的提示后，可以点击“保存”按钮将文件内容框中的文字导出到用\n	户指定的文件中。\n    6、输出中包括三个方面的内容：分词后的原句子；原句子的拼音标注，数字、非\n	中文和标点原样输出；如果查不到该字则显示“***”。（其中拼音后的数字表示\n	音调，1-4分别对应1-4声，数字5表示轻声。	\n	输出文件编码默认为UTF8）\n◇性能表现：\n    1、对于多音字的标注准确率在90%左右；\n    2、支持最大文件：50KB.\n    3、分词效率：>10KB/S.\n    4、支持视窗中文版，不支持任何外文版操作系统。\n");

    table = gtk_table_new(10,10,FALSE);
    gtk_container_add(GTK_CONTAINER(dialog),label);

    gtk_widget_show_all(dialog);
}


/***************************************************************************************************
 on_about_activate : to accept the action from the window's about menu.
 parameter : GtkMenuItem *menuitem
             Accept the action of the specific GTK components. 

             gpointer data
             A pointer designated by programmers. 
 return type : null.
 detail descrpition : Check the copyright version information.           
****************************************************************************************************/
void on_about_activate (GtkMenuItem *menuitem,gpointer data){
    GtkWidget * table;
    GtkWidget * button;
    GtkWidget * dialog;
    GtkWidget * label;
    GtkWidget * image;
    GdkPixbuf * pixbufv;

    dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(dialog),400,400);
    gtk_window_set_title(GTK_WINDOW(dialog),"关于 Wasabi");
    gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER);
    label = gtk_label_new("欢迎使用Wasabi V1.0   \n\n开发人员：LI Yi,  LI Wei,  LI Xuewen,  LU Xu   \n\n2010年1月 于bjtu");
    pixbufv = gdk_pixbuf_new_from_inline (-1, logo2_inline, TRUE, NULL);
    image = gtk_image_new_from_pixbuf(pixbufv);
    button = gtk_button_new_from_stock(GTK_STOCK_OK);
    g_signal_connect_swapped(GTK_OBJECT(button),
					"clicked",
					G_CALLBACK(gtk_widget_destroy),
					dialog);
    table = gtk_table_new(10,10,FALSE);
    gtk_container_add(GTK_CONTAINER(dialog),table);
    gtk_table_attach_defaults(GTK_TABLE(table),image,0,10,0,7);
    gtk_table_attach_defaults(GTK_TABLE(table),label,0,10,7,9);
    //gtk_table_attach_defaults(GTK_TABLE(table),button,9,10,9,10);

    gtk_widget_show_all(dialog);

}

